home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Power Tools for Macintosh
/
Power Tools for Macintosh (SoftBit)(1992).iso
/
Applications
/
Alpha 4.01
/
ACMDS
/
Time⁄Date.c
< prev
next >
Wrap
C/C++ Source or Header
|
1990-08-15
|
4KB
|
139 lines
/****************************************************************
* *
* Paste Time/Date - paste the current time, or current date *
* *
* Copyright © 1990 Karl J. Smith. All Rights Reserved *
* *
* email: ksmith@jarthur.claremont.edu *
* *
* 8/10/90 *
* *
* When debugging, set the project type to application, *
* and add the ANSI project. *
* *
* When all your bugs are out, 'undef' DEBUG, set the project *
* type to Code Resource, with type = ACMD, name = <the name *
* of the function>, file type to 'AEXT', and the purgeable *
* flag set to true. *
* *
* Also, you need to remove the ANSI project from the ACMD *
* project and replace it with the ANSI-A4 project if you use *
* any functions in ANSI, such as strlen. *
* *
* If you are not using THINK C, I'm not quite sure what you *
* should do. :-) *
* *
****************************************************************/
#undef DO_TIME
#define DO_DATE
/*
** If you want a time ACMD, define DO_TIME. If you want a date ACMD,
** define DO_DATE. If you want time and date, create a macro to insert both.
**
** Both of these ACMD's take input in the form of a single character at
** the beginning of the stream of chars passed to them. The rest of the
** characters are ignored.
**
** The Time ACMD will include seconds if 'S' is the first character.
** Any other character will return the time without seconds.
**
** The Date ACMD will return short, long, or abbrev forms if the first
** character is 'S', 'L', or 'A' respectively. 'A' will be assumed by
** default.
*/
#undef DEBUG
#include <stdio.h>
#include <string.h>
/* Prototypes */
char *
#ifdef DEBUG
dummy(char *inStr);
#else DEBUG
main(char *inStr);
#endif DEBUG
char *
#ifdef DEBUG
dummy(inStr)
#else DEBUG
main(inStr)
#endif DEBUG
char *inStr;
{
long int theTime;
char *resultString;
resultString = (char *)NewPtr(256L);
if (resultString == NULL)
{
SysBeep(5);
return(inStr);
}
GetDateTime(&theTime);
#ifdef DO_TIME
IUTimeString(theTime, *inStr == 'S', resultString);
#endif DO_TIME
#ifdef DO_DATE
switch (*inStr)
{
case 'S' : IUDateString(theTime, shortDate, resultString);
break;
case 'L' : IUDateString(theTime, longDate, resultString);
break;
default : IUDateString(theTime, abbrevDate, resultString);
break;
}
#endif DO_DATE
DisposPtr(inStr);
PtoCstr(resultString);
return(resultString);
}
#ifdef DEBUG
char * ConvertRtoN(char *theStr);
char * ConvertRtoN(theStr)
char *theStr;
{
char *currentChar;
for (currentChar = theStr;*currentChar != 0; currentChar++)
if (*currentChar == '\r')
*currentChar = '\n';
}
main()
{
char *str = "ANice\rand\reasy\rABCDEFGHIJKLMNOPQRSTUVWXYZ\rabcdefghijklmnopqrstuvwxyz";
char *ret;
char once[255];
strcpy(once, str);
ret = dummy(once);
ConvertRtoN(ret); /* Convert '\r' to '\n' so we can see them in a printf */
ConvertRtoN(str);
printf("The original is:\n\n%s", str);
printf("\n----\n\nThe result is:\n\n%s", ret);
}
#endif DEBUG